Execute MATLAB function in Automation server 您所在的位置:网站首页 feval method Execute MATLAB function in Automation server

Execute MATLAB function in Automation server

2024-07-11 07:05| 来源: 网络整理| 查看: 265

Feval (COM)

Execute MATLAB function in Automation server

expand all in pageSynopsisIDL Method SignatureHRESULT Feval([in] BSTR functionname, [in] long nargout, [out] VARIANT* result, [in, optional] VARIANT arg1, arg2, ...)Microsoft Visual Basic ClientFeval(String functionname, long numout, arg1, arg2, ...) As ObjectMATLAB Client

result = Feval(h,'functionName',numout,arg1,arg2,...)

Description

result = Feval(h,'functionName',numout,arg1,arg2,...) executes MATLAB® function functionName in the Automation server attached to h. The function name is case-sensitive. If functionName does not have input arguments, consider calling Execute instead.

COM functions are available on Microsoft® Windows® systems only.

Indicate the number of outputs returned by the function in a 1-by-1 double array, numout. The server returns output from the function in the cell array, result.

You can specify as many as 32 input arguments to be passed to the function. These arguments follow numout in the Feval argument list. The following table shows ways to pass an argument.

Passing Mechanism

Description

Pass the value itself

To pass any numeric or character value, specify the value in the Feval argument list:

a = Feval(h,'sin',1,-pi:0.01:pi);

Pass a client variable

To pass an argument assigned to a variable in the client, specify the variable name alone:

x = -pi:0.01:pi; a = Feval(h,'sin',1,x);

Reference a server variable

To reference a variable defined in the server, specify the variable name followed by an equals (=) sign:

PutWorkspaceData(h,'x','base',-pi:0.01:pi); a = Feval(h,'sin',1,'x=');

MATLAB does not reassign the server variable.

Examples

expand all

Call strcat from Visual Basic .NET ClientOpen Live Script

This example shows how to pass string arguments to the MATLAB strcat command using Feval.

Create a Visual Basic® .NET application with the following code.

type fevalPassingArguments.vbDim Matlab As Object Dim out As Object out = Nothing Matlab = CreateObject("matlab.application") Matlab.Feval("strcat",1,out,"hello"," world") Dim clistr As String clistr = " world" Matlab.Feval("strcat",1,out,"hello",clistr) Matlab.PutCharArray("srvstr","base"," world") Matlab.Feval("strcat",1,out,"hello","srvstr=") Defining Feval Return ValuesOpen Live Script

This example shows how to return the filepath, name, and ext arguments from the fileparts function.

Feval returns data from the evaluated function in a cell array. The cell array has one row for every return value. You control the number of return values using the Feval numout argument.

Create a Visual Basic .NET client with the following code.

type fevalDefiningFevalReturnValues.vbDim Matlab As Object Dim out As Object Matlab = CreateObject("matlab.application") Matlab.Feval("fileparts",3,out,"d:\work\ConsoleApp.cpp") Modified Server VariablesOpen Live Script

This example shows how to return a modified server variable.

Create a matrix, A, in the server.

Reshape A.MATLAB interprets A in the expression 'A=' as a server variable name.

The reshape function does not modify variable A. A is unchanged.

To get the result of the reshape function, use the numout argument to assign the value to C.

Create a Visual Basic .NET application with the following code.

type fevalModifiedServerVariables.vbDim Matlab As Object Dim rows As Double Dim cols As Double Dim out As Object out = Nothing Dim data(7) As Double For i = 0 To 7 data(i) = i * 15 Next i Matlab = CreateObject("matlab.application") Matlab.PutWorkspaceData("A", "base", data) rows = 4 cols = 2 Matlab.Feval("reshape", 1, out, "A=", rows, cols) Tips

To display the output from Feval in the client window, assign a return value.

Version History

Introduced before R2006a

See Also

Execute | PutFullMatrix | GetFullMatrix | PutCharArray | GetCharArray

TopicsConvert COM Types to MATLAB TypesConvert MATLAB Types to COM Types


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有